package com.csdj.t309tgspringboot.service;

import com.csdj.t309tgspringboot.entity.Comments;
import com.csdj.t309tgspringboot.entity.CommentsExample;
import com.csdj.t309tgspringboot.mapper.CommentsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentService implements ICommentsService{
    @Resource
    private CommentsMapper commentsMapper;
    private CommentsExample commentsExample;

    @Override
    public Integer insertC(Comments comments) {
        Integer result = commentsMapper.insert(comments);
        if(result>0){
            return result;
        }
        return 0;
    }

    @Override
    public List<Comments> selC() {
        commentsExample = new CommentsExample();
        commentsExample.createCriteria();
        List<Comments> selCom = commentsMapper.selectByExample(commentsExample);
        if(selCom!=null){
            return selCom;
        }
        return null;
    }

    @Override
    public List<Comments> selSonC(Integer pid) {
        commentsExample = new CommentsExample();
        commentsExample.createCriteria().andCommentsPidEqualTo(pid);
        List<Comments> selSonCom = commentsMapper.selectByExample(commentsExample);
        if(selSonCom!=null){
            return selSonCom;
        }
        return null;
    }
}
